import { Toast } from 'vant'
import { createRouter, createWebHistory } from 'vue-router'

const routes = [{
	path: '/',
	component: () =>
		import('../pages/MyHome/MyHome.vue')
},
{
	path: '/home',
	component: () =>
		import('../pages/MyHome/MyHome.vue')
},
{
	// 订单列表
	path: '/order',
	component: () =>
		import('../pages/MyOrder/MyOrder.vue'),
	  meta:{
        isAuth:true
		}
},
{
	// 我的
	path: '/mine',
	component: () =>
		import('../pages/Mine/Mine.vue'),
	 meta:{
        isAuth:true
		}
}, {
	// 购物车
	path: '/cart',
	component: () =>
		import('../pages/MyCart/MyCart.vue'),
	 meta:{
        isAuth:true
		}
}, {
	// 店铺页面
	path: '/store',
	component: () =>
		import('../pages/MyStore/MyStore.vue'),
	 meta:{
        isAuth:true
		}
},{
	// 结算
	path: '/createorder',
	component: () =>
		import('../pages/createOrder/CreateOrder.vue')
},
{
	// 结算
	path: '/blank',
	component: () =>
		import('../components/Blank.vue')
},
{
	// 地址管理
	path: '/address',
	component: () =>
		import('../pages/Address/AddRess.vue'),
	 meta:{
        isAuth:true
		}
},// 地址编辑
{path: '/addressedit',
component: () =>
	import('../pages/AddressEdit/AddressEdit.vue'),
 meta:{
        isAuth:true
		}
},
//账号管理
{path: '/userInfoEdit',
component: () =>
	import('../pages/userInfoEdit/userInfoEdit.vue'),
 meta:{
        isAuth:true
		}
},
//登录
{path: '/login',
component: () =>
	import('../pages/Login/login.vue'),
},
//注册
{path: '/regist',
component: () =>
	import('../pages/Regist/regist.vue'),
}

]


//路由守卫 

 

const router = createRouter({
	history: createWebHistory(),
	routes
})

router.beforeEach((to,from,next)=>{
      if(to.meta.isAuth){
				 if(localStorage.isLogin=='1'){
					 next()
				 }else{
					Toast('请先登录')
					router.push('/login')
				 }
			}
			else{
				next()
			}
})



export default router